import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
        'upToken',
		'upUserInfo'
    ]),
	getEmail(e){
		var obj = this.emailList[e.detail.value]
		console.log(obj)
		this.select = obj['label']
		let number = parseInt(e.detail.value)
		this.current = number >= 0 ? number : 0
	},
	handlerChoose(){
		this.agree = !this.agree
	},
	toLogin(){
		uni.navigateTo({
			url: '/pages/publics/emailLogin'
		})
	},
	//用户协议
	toUserAgreement(){
		uni.navigateTo({
			url: '/pages/publics/userAgreement'
		})
	},
	privacyAgreement(){
		uni.navigateTo({
			url: '/pages/publics/privacyAgreement'
		})
	},
	
    submitForm() {
        let that = this
        if (that.loading) {
            that.$toast.msg('请求中...', {
                icon: 1
            })
            return false
        }
		that.formData.email = that.formData.email+ that.select
        that.loading = true
			that.$httpRequest.request({
			    that: that,
			    url: 'h5/registerEmail',
			    params: that.formData,
			    success: res => {
			        that.loading = false
			        if (res.code === that.$httpConfig.SUCCESS_CODE) {
						uni.navigateTo({
							url:'/pages/publics/emailLogin'
						})
			            
			        } else {
			            that.$toast.alert({
			                content: res.message,
			                callback: result => {

			                }
			            })
			        }
			    }
			})

    },
	getCode() {
	    let that = this
		
	    if (that.loading) {
	        that.$toast.msg('请求中...', {
	            icon: 1
	        })
	        return false
	    }
	    that.loading = true
	    that.$httpRequest.request({
	        that: that,
	        url: 'h5/sendMail',
	        params: {
	            email: that.formData.email+ that.select,
				type:1,//1 注册，2 忘记密码
	        },
	        success: res => {
	            that.loading = false

				
	            if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.getTxt = 60
					that.loopNum()
	            }else{
					that.$toast.msg(res.message, {
					  icon: 1
					})
				}
	        }
	    })
	},
	loopNum() {
		let that = this
	    that.intervalObj = setInterval(() => {
			that.num--
			if (that.num <= 0) {
				clearInterval(that.intervalObj)
				that.num = 60
				that.getTxt = "获取"
			}
	    }, 1000)
		
	},
	toOtherLogin(){
		uni.navigateTo({
			url: '/pages/publics/otherLogin'
		})
	},
	toReset(){
		uni.navigateTo({
			url: '/pages/publics/reset'
		})
	},
}
